<%@ page language="java" import="com.newcrm.config.*,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String customerType = request.getParameter("customerType");
  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<User> users = companyInfo.users;
  // 获取产品信息
  ProductInfo productInfo = Config.getInstance().productInfo;
  String productName =  productInfo.productName;
  String productId = productInfo.productId;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>导入客户信息</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script>
    $(function() {
      $("#partiesMenu").addClass("selected");
      $("div.import_option h1 a").click(function(e){
        e.preventDefault();
        var _format = $(this).attr("format");
        $("#file_format").val(_format);
        $("#csvIntro, #excelIntro").hide();
        if (_format == "csv") {
          $("#csvIntro").show();
        } else {
          $("#excelIntro").show();
        }
        $("#sheet_content_list").hide();
        $("#sheet_content").show();
      });
      $("#cancel_link").click(function(e){
        $("#sheet_content_list").show();
        $("#sheet_content").hide();
      });
      $("#new_contact_import").submit(function(event){
        if ($("#file").val().length == 0) {
          alert("请选择需要导入的文件");
          return false;
        }

        var _visible = $("#new_contact_import input[name='visible']:checked").val();
        if (_visible == "<%=Const.VISIBLE_PERSON%>") {
          var _permissionsIds = $("#new_contact_import input:checked[name=permissionsId]").map(function() {
            return $(this).val();
          }).get().join();

          if (_permissionsIds == "") {
            alert("请选择导入客户的负责人");
            return false;
          }
        }

        $("#import_button").parent().addClass("busy");
        return true;
      });
      $("#import_button").click(function(e){
        $("#new_contact_import").submit();
      });
    });
  </script>
</head>
<body class="parties former_sheet">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <table>
    <tr>
      <td class="main-body">
        <div class="topnavi"><div class="leftMenu"><span>导入客户信息</span></div></div>
        <div class="searchresult">
          <div class="sheet_content form_section" id="sheet_content_list">
            <p class="intro">选择下面的文件，便捷地导入联系人/公司信息</p>
            <div class="import_option">
              <h1><a href="#/csv" format="<%=Const.FILE_TYPE_CSV%>">导入CSV文件</a></h1>
              <p>方便地导入CSV格式的文件。</p>
            </div>
            <div class="import_option">
              <h1><a href="#/xls" format="<%=Const.FILE_TYPE_EXCEL%>">导入Excel文件</a></h1>
              <p>支持最新版的Excel格式。</p>
            </div>
            <p class="submit">
              <a href="<%=request.getContextPath()%>/parties" class="button blue"><i class="fa fa-reply"></i> 取消导入</a>
            </p>
          </div>
          <div class="edit" id="sheet_content" style="display:none;">
            <form action="<%=request.getContextPath()%>/customerimports/upload" enctype="multipart/form-data" id="new_contact_import" method="post">
              <p class="intro" id="csvIntro" style="display:none;">请选择CSV文件 &nbsp;&nbsp;<a href="<%=request.getContextPath()%>/<%=productId%>-template.csv">下载<%=productName%>导入数据模板文件</a></p>
              <p class="intro" id="excelIntro" style="display:none;">请选择Excel文件 &nbsp;&nbsp;<a href="<%=request.getContextPath()%>/<%=productId%>-template.xls">下载<%=productName%>导入数据模板文件</a></p>
              <div class="form_section">
                <p>
                  <input id="file_format" name="fileType" type="hidden" value="<%=Const.FILE_TYPE_CSV%>" />
                  <input id="file" name="file" size="30" type="file" />
                </p>
              </div>
              <div class="edit_section">
                <div class="form_section">
                  <h5>查看权限设置</h5>
                  <div>
                    <div class="scope">
                      <label><input name="visible" type="radio" value="<%=Const.VISIBLE_EVERYONE%>" /> 公海数据</label>
                      <div class="editor">
                        <select name="groupPermissionsId">
                          <jsp:include page="commonPublicDataSelection.jsp" flush="true"/>
                        </select>
                      </div>
                    </div>
                    <div class="scope ">
                      <label><input checked="checked" name="visible" type="radio" value="<%=Const.VISIBLE_PERSON%>" /> 私有数据(可以勾选多个员工平均分配)</label>
                      <div class="editor">
                        <label id="shareUserId_<%=user.userId%>"><input checked="checked" name="permissionsId" type="checkbox" value="<%=user.userId%>" /> 我</label>
                        <%
                          String groupName = null;
                          for (User u : users) {
                            if (u.userId.equals(user.userId)) {
                              continue;
                            }
                            if (!companyInfo.isGroupAdmin(user, u.groupId)) {
                              continue;
                            }
                            String gn = companyInfo.getGroupName(u);
                            if (gn != null && !gn.equals(groupName)) {
                                groupName = gn;  %>
                        <p><%=Util.HTMLEncode(groupName)%></p>
                           <%}%>
                        <label id="shareUserId_<%=u.userId%>"><input name="permissionsId" type="checkbox" value="<%=u.userId%>" /> <%=Util.HTMLEncode(u.name)%></label>
                        <%}%>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <p class="submit">
                <a href="#" id="import_button" class="button blue"><i class="fa fa-plus"></i> 立即导入</a>
                <span>或者</span>
                <a href="#" id="cancel_link" class="admin">取消</a>
              </p>
            </form>
          </div>
        </div>
      </td>
    </tr>
    </table>
  </div>
</body>
</html>